package algorithm.子数组达到规定累加和的最大长度系列问题.转圈问题;

public class PrintStar {

    public static void printStar(int N){

        int[][] arr = new int[N][N];
        int tmp = N % 2 == 0? N / 2 : N / 2 + 1;
        for (int i = 0; tmp - i * 2 > 0; i++) {
            int length = N - i * 4;
            for (int j = i * 2; j < i * 2 + length; j++) {
                arr[i * 2][j] = 1;
            }
            for (int j = i * 2; j < i * 2 + length; j++) {
                arr[j][i * 2 + length - 1] = 1;
            }
            for (int j = i * 2 + 1; j < i * 2 + length; j++) {
                arr[i * 2 + length - 1][j] = 1;
            }
            for (int j = i * 2 + 2; j < i * 2 + length; j++) {
                arr[j][i * 2  + 1] = 1;
            }
        }

        for (int i = 0; i < N; i++) {
            for (int j = 0; j < N; j++) {
                if(arr[i][j] == 1)
                    System.out.print("*  ");
                else
                    System.out.print("   ");
            }
            System.out.println();
        }

    }

    public static void main(String[] args) {
        printStar(12);
    }
}
